﻿if (typeof Axis == "undefined") Axis = {};
if (typeof Axis.View == "undefined") Axis.View = {};
if (typeof Axis.View.SKDV == "undefined") Axis.View.SKDV = {};
var RowPerPage = 2;
Axis.View.SKDV.List = {
    Content: '',
    Init: function () {
        var thisObj = this;
        this.GetTopNews();
        $('.news_detail_mini_more').bind('click', function () {
            thisObj.ShowDetail();
            $(this).hide();
        });
        $('.news_detail_mini_title').bind('click', function () {
            $('.news_detail_mini_more').click();
            return false;
        });
        $('#imageTop1').live('click', function () {
            $('.news_detail_mini_more').click();
            return false;
        });
    },
    ShowDetail: function () {
        $(".news_detail_mini_description").html(this.Content);
        $(".news_detail_mini_more").hide();
    },
    GetTopNews: function () {
        var objThis = this;
        $.Ajax({
            type: "POST",
            url: '/Views/News/Service/NewsService.asmx/GetTop1',
            cache: false,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: '{' + $.string.Format('"catID":{0}', CateID) + '}',
            success: function (pData) {
                if (pData !== null)
                    if (pData.d !== null) {
                        var data = eval("(" + pData.d + ")");
                        objThis.ShowNewsList(data);
                    }
            }
        });
    },
    GetCloundTag: function (newsID) {
        var pData = '{' + $.string.Format('"NewsID":{0}', newsID) + '}';
        var thisObj = this;
        $.ajax({
            url: '../TagCloud/Service/ClounbTagService.asmx/GetListByNewsID',
            type: 'POST',
            data: pData,
            cache: false,
            async: false,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (pData, textStatus, jqXHR) {
                if (pData !== null)
                    if (pData.d !== null) {
                        var data = eval("(" + pData.d + ")");
                        thisObj.BuildCloundTab(data);
                    }

            },
            beforeSend: function (jqXHR, settings) {
            },
            error: function (jqXHR, textStatus, errorThrown) {
            },
            complete: function (XMLHttpRequest, textStatus) {
            }
        });

    },
    BuildCloundTab: function (data) {

        var objThis = this;
        var pattern = '  <span class="news_detail_mini_tag_value"><a href="../TagCloud/{0}">{1}</a></span>';
        var htmlContent = "";
        $.each(data, function (index, item) {
            htmlContent += $.string.Format(pattern, item.ID, item.Text);
        });
        $(".news_detail_mini_tag").append(htmlContent);
    },
    ShowNewsList: function (data) {
        var thisObj = this;
        if (data.length > 0) {
            thisObj.ViewBoxFirst(data[0]);
        }

    },
    ViewBoxFirst: function (data) {
        this.GetCloundTag(data.ID);
        try {
            $(".news_detail_mini_image").html($.string.Format('<img class="imgNewsDetailMini" id="imageTop1" src="{0}" />', data.Image));
            $(".news_detail_mini_title").html($.string.Format('<span>{0}</span>', data.Title));
            $(".news_detail_mini_description").html(data.Summary);
            $(".news_detail_mini_date").html($.string.Format('Cập nhật lúc {0}', $.CFormat.FormatDateSerializer(data.WritenDate)));
            this.Content = data.Content;
        } catch (ex) {

        }
    },
    GetRandom: function (min, max) {
        return Math.round((Math.random() * (max - min)) + min);
    }
}
$(function () {
    Axis.View.SKDV.List.Init();
    $('#Project-Slider').jshowoff({
        animatePause: true,
        autoPlay: true,
        changeSpeed: 2000,
        controls: true,
        cssClass: 'thumbFeatures',
        effect: 'slideLeft',
        hoverPause: false,
        links: false,
        speed: 9000
    });
});